package com.example.tests;

import static org.testng.Assert.fail;

import java.util.Random;
import java.util.Set;
import org.testng.annotations.Test;
import com.example.data.ContactData;

public class ContactRemovalTests extends TestBase {
	@Test
	public void contactRemovalTest() throws Exception {
		//first go to home page and get list of contacts
		
		Set<ContactData> oldList = manager.getContactHelper().getContactsList();
		//continue test if contact list is not empty
		int oldListSize = oldList.size();
		if (oldListSize > 0) {
			Random rnd = new Random();
			int numberOfContactToDelete = rnd.nextInt(oldListSize);
			//then open first contact for edit and delete it
			ContactData contactToDelete = manager.getContactHelper().deleteContactByNumber(numberOfContactToDelete);
			Set<ContactData> newList = manager.getContactHelper().getContactsList();
			verifyContactRemoved(oldList, contactToDelete, newList);
		} else {
			//fail the test if contact list is empty
			fail("Contacts list is empty");
		}
	}

}